#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int n, m;
int a[N], b[N], c[N], d[N];
void solve() {
  cin >> n;
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, n) cin >> b[i];
  vector<int> e;
  rep(i, 1, n) if (a[i] == b[i]) e.push_back(i);
  if (e.size() > 1 || (e.size() == 1 && n % 2 == 0)) {
    cout << -1 << endl;
    return;
  }
  vector<pii> ans;
  if (e.size()) {
    int x = e[0];
    int y = (n + 1) / 2;
    if (x != y) {
      ans.push_back(pii(x, y));
      swap(a[x], a[y]);
      swap(b[x], b[y]);
    }
  }
  map<int, int> mpa, mpb;
  rep(i, 1, n) mpa[a[i]] = i;
  rep(i, 1, n) mpb[b[i]] = i;
  rep(i, 1, n / 2) {
    int x = a[i], y = b[i];
    if (mpa[y] != mpb[x]) {
      cout << -1 << endl;
      return;
    }
    int p1 = mpa[y];
    int p2 = n + 1 - i;
    if (p1 != p2) {
      ans.push_back(pii(p1, p2));
      swap(a[p1], a[p2]);
      swap(b[p1], b[p2]);
      mpa[a[p1]] = p1;
      mpa[a[p2]] = p2;
      mpb[b[p1]] = p1;
      mpb[b[p2]] = p2;
    }
  }
  cout << ans.size() << endl;
  for (pii p : ans) cout << p.first << ' ' << p.second << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}